﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using jQXBM.MVC.Models;

namespace jQXBM.MVC.Controllers
{
    public class CustomerController : Controller
    {
        //
        // GET: /Customer/

        public ActionResult Index()
        {
            return View();
        }

        [OutputCache(Duration = 0)]
        public ActionResult getCustomerList()
        {
            List<Customer> customerList = new List<Customer>();
            for (int idx = 0; idx < 10; idx++)
            {
                Models.Customer customer = new Models.Customer();
                customer.id = idx;
                customer.Name = "CustomerName" + idx.ToString();
                customer.Surname = "CustomerSurname" + idx.ToString();
                customer.Address = "CustomerStreet" + idx.ToString();
                customer.ordersList = new List<Models.Order>();
                customerList.Add(customer);
            }
            return Json(customerList, JsonRequestBehavior.AllowGet);
        }


        public ActionResult custDetailsPanelExt(bool extended)
        {
            return extended?PartialView("Index_CustomerDetailsExt"): PartialView("Index_CustomerDetails");
        }

        [OutputCache(Duration=0)]
        public ActionResult getCustomer(int id)
        {
            Models.Customer customer = new Models.Customer();
            customer.id = id;
            customer.Name = "CustomerName" + id.ToString();
            customer.Surname = "CustomerSurname" + id.ToString();
            customer.Address = "CustomerStreet" + id.ToString();
            customer.ordersList = new List<Models.Order>();
            for (int i = 0; i < 5; i++)
            {
                customer.ordersList.Add(new Order() { date = DateTime.Now.ToShortDateString(), number = Guid.NewGuid().ToString() });
            }
            return Json(customer, JsonRequestBehavior.AllowGet);
        }

        [OutputCache(Duration = 0)]
        [HttpPost]
        public ActionResult SaveCustomer(Models.Customer customer)
        {
            customer.Name += "Just Saved";
            return Json(customer);
        }
    }
}
